import { _decorator, Component, Label, Node, resources, Sprite, spriteAssembler, SpriteFrame } from 'cc';
import { UILayerMgr } from './UILayerMgr';
import { StartSceneGameMgr } from './StartSceneGameMgr';
import { AudioMgr } from '../utils/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('EquipCellItem')
export class EquipCellItem extends Component {

    @property(Label)
    levelLabel:Label;
    @property(Sprite)
    sp:Sprite;
    @property(Node)
    isPutOnIcon:Node=null;
    @property(Node)
    emeraldNode:Node=null;
    @property(Sprite)
    qualityCellBg:Sprite;

    equip;

    init(data,isDisplayPutOnIcon=true) {
        this.equip=data;
        this.levelLabel.string = data.enhanceLevel

        if (this.equip.enhanceLevel==0) {
            this.emeraldNode.active=false;
        }
        else{
            this.emeraldNode.active=true;
        }

        resources.load(`equipImg/${data.equipType}/spriteFrame`,SpriteFrame,(err,res)=>{
            this.sp.spriteFrame=res;
        })

        resources.load(`qualityCellBg/${data.equipTp.quality}/spriteFrame`,SpriteFrame,(err,res)=>{
            this.qualityCellBg.spriteFrame=res;
        })

        if (isDisplayPutOnIcon==true) {
            if (data.ownerRoleId!=-1) {
                this.isPutOnIcon.active=true;
            }
            else{
                this.isPutOnIcon.active=false;
            }
        }
        else{
            this.isPutOnIcon.active=false;
        }
        
    }

    onclickThisCom() {
        AudioMgr.ins.playOneShot("audio/clickBtn",0.8);

        UILayerMgr.getIns.openUILayer("desEquipPanel", this.equip)
    }

}


